package com.hutao.chargingpile.spread.service.impl;

import com.alibaba.excel.EasyExcel;
import com.hutao.chargingpile.spread.listener.ExcelCpClientlistener;
import com.hutao.chargingpile.spread.pojo.entity.CpClient;
import com.hutao.chargingpile.spread.mapper.CpClientMapper;
import com.hutao.chargingpile.spread.pojo.entity.ExcelCpClient;
import com.hutao.chargingpile.spread.service.CpClientService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author HuTao
 * @since 2023-03-28
 */
@Service
@Slf4j
public class CpClientServiceImpl extends ServiceImpl<CpClientMapper, CpClient> implements CpClientService {

    @Resource
    private CpClientMapper cpClientMapper;



    @Override
    public List<CpClient> findAll(Map<String,Object> map) {
        return cpClientMapper.findAll(map);
    }

    @Override
    public int findCount(Map<String,Object> map) {
        return cpClientMapper.findCount(map);
    }


    @Transactional(rollbackFor = {Exception.class})
    @Override
    public void importData(InputStream inputStream) {
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(inputStream, ExcelCpClient.class, new ExcelCpClientlistener(baseMapper)).sheet().doRead();
        log.info("importData finished");
    }

    /**
     * 添加用户信息
     * @param cpClient
     */
    @Override
    public void addClient(CpClient cpClient) {
            cpClientMapper.addClient(cpClient);

    }

    /**
     * 下拉框回显数据
     * @return
     */
    @Override
    public List<CpClient> find() {
        return cpClientMapper.find();
    }

     //回显投资商下拉框
    @Override
    public List<CpClient> findInvestor() {
        return cpClientMapper.findInvestor();
    }

   //回显性别下拉框
    @Override
    public List<CpClient> findSex() {
        return cpClientMapper.findSex();
    }

//    @Override
//    public void removeById(long id_delete) {
//        cpClientMapper.removeById(id_delete);
//    }

}
